@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 角色列表  </span></h1>
    <hr>

    <table class="table table-bordered  table-hover" id="tent">
        <tr>
            <th>ID</th>
            <th>角色</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        @foreach($result as $v)
            <tr>
                <th>{{$v->id}}</th>
                <th>{{$v->or_name}}</th>
                <th>
                    @if(($v->start) == 0)
                        <button class="btn btn-success" onclick="start({{$v->id}},{{$v->start}})">启用</button>
                    @elseif(($v->start) == 1)
                        <button class="btn btn-danger" onclick="start({{$v->id}},{{$v->start}})">禁用</button>
                    @endif
                </th>
                <th>
                    <button class="btn btn-danger" onclick="del({{$v->id}})">删除</button>
                    <a href="/role/update/{{$v->id}}" class="btn btn-primary">编辑</a>
                    <a href="/role/look/{{$v->id}}" class="btn btn-primary">权限详情</a>
                </th>
            </tr>
        @endforeach
    </table>

    <script>
        function start($id, $start) {
            var id = $id;
            var start = $start;

            $.ajax({
                type: 'get',
                url: "{{url('/role/start')}}/" + id + '/' + start,
                data: [id, start], //发送请求数据
                success: function (data) {
                    window.location.href = '{{url('/role')}}';
                },
                error: function () {
                    alert('ajax请求失败');
                }
            });
        }


        function del($id) {
            var id = $id;

            $.ajax({
                type: 'get',
                url: "{{url('/role/del')}}/" + id,
                data: id, //发送请求数据
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        $("table#tent tr").click(function () {
                            $(this).remove();
                        });
                        window.location.href = '{{url('/role')}}';
                    } else {
                        alert('删除失败');
                    }
                },
                error: function () {
                    alert('ajax请求失败');
                }
            });
        }
    </script>

@endsection
